import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {
  /// 获取存储权限
  Future<bool> getStoragePermission() async {
    late PermissionStatus myPermission;

    /// 读取系统权限
    if (defaultTargetPlatform == TargetPlatform.iOS) {
      myPermission = await Permission.photosAddOnly.request();
    } else {
      myPermission = await Permission.storage.request();
    }
    if (myPermission != PermissionStatus.granted) {
      return false;
    } else {
      return true;
    }
  }

  void checkPermission() async {
    // 请求存储权限
    final permissionState = await getStoragePermission();
    if (permissionState) {
      // 权限被授予
    } else {
      // 权限被拒绝 打开手机上该App的权限设置页面
      openAppSettings();
    }
  }
}